package com.modemMgr.dao;

import java.util.List;

import com.modemMgr.util.DBAccessor;
import com.modemMgr.vo.PrivilegeInfo;

public class PrivilegeDAO  extends BaseDAO{	
	public PrivilegeDAO(DBAccessor dbAccessor) {
		super(dbAccessor);
	}

	public List<PrivilegeInfo> getMenuList(int parentId) throws Exception
	{
		String sql = "select i.* from privilege_infos i where i.is_valid = 1 and i.privilege_type = 0 and i.parent_pri_id = ?";
		return dbAccessor.queryList(PrivilegeInfo.class, sql, new Object[]{parentId});
	}
	
	public List<PrivilegeInfo> getMenuListByRoleId(int roleId, int parentId) throws Exception
	{
		String sql = "select i.* from privilege_infos i, role_privileges r ";
        sql += "where i.is_valid = 1 and i.privilege_type = 0 ";
		sql += "and i.privilege_id = r.privilege_id and r.role_id = ? and i.parent_pri_id = ?";
		return dbAccessor.queryList(PrivilegeInfo.class, sql, new Object[]{roleId, parentId});
	}
}
